home *** CD-ROM | disk | FTP | other *** search
- #include "DuckGame.h"
- #include <setupa4.h>
- #include <A4Stuff.h>
- #include <new.h>
- #include "blitter.h"
- #include "GWorldUtils.h"
- #include "StAllowDraw.h"
- #include <patches.h>
- #include "BlasteroidsGame.h"
-
- static CSpriteGame* gGame = NULL;
- pascal void InitGame();
-
- void* operator new (size_t size)
- {
- return NewPtrSys(size);
- }
-
- void operator delete(void* obj)
- {
- if(obj != NULL){
- DisposePtr((Ptr)obj);
- }
- }
-
- typedef pascal void (*SystemTaskProc)();
- static long gOldSystemTask;
-
- static pascal void newSystemTask()
- {
- EnterCallback();
-
- if(LMGetCurApRefNum() > 0){
- if(gGame != NULL){
- delete gGame;
- gGame = NULL;
- }
- }
-
- (*(SystemTaskProc)gOldSystemTask)();
-
- ExitCallback();
- }
-
- pascal void InitGame()
- {
- // EnterCodeResource();
-
-
- THz saveZone = GetZone();
- SetZone(SystemZone());
- StAllowDraw allowDraw;
-
- PrepareCallback();
- gOldSystemTask = PatchTrap(_SystemTask,(long)newSystemTask);
- // Handle h = Get1IndResource('INIT',1);
- // if(h != NULL){
- // DetachResource(h);
-
- if (*((long*)0x178) != 0)
- gGame = new CDuckGame;
- else
- gGame = new CBlasteroidsGame;
- OSErr err = gGame->Initialize();
- if(err == noErr){
- // GWorldPtr gWorld;
- // RgnHandle mask;
-
- // err = NewCIconGWorld(128,&gWorld,&mask);
- // if(err == noErr){
- // HLock((Handle)mask);
- // gGame->IntroduceExtensionIcon(gWorld,mask);
- gGame->StartGame();
- // }
- }
- // }
-
- SetZone(saveZone);
- // ExitCodeResource();
- }
-
- pascal void Blit(short iconID)
- {
- gGame->StopGame();
-
- StAllowDraw allowDraw;
- StSaveGWorld saveGWorld;
- OSErr err = noErr;
- THz saveZone = GetZone();
- Rect bounds = {0,0,32,32};
- GWorldPtr newGWorld;
- RgnHandle newMask;
- short jbTempVBLMask;
-
- SetZone(SystemZone());
- jbTempVBLMask = *(short *)0x160;
- *(short *)0x160 |= 0x4000;
-
- ObscureCursor();
-
- err = NewLockedGWorld(&newGWorld,0,&bounds,NULL,NULL,0);
- if(err == noErr){
- SetGWorld(newGWorld,NULL);
- PlotIconID(&bounds, 0, 0, iconID);
- newMask = NewRgn();
- IconIDToRgn(newMask,&bounds,0,iconID);
- HLock((Handle)newMask);
-
- gGame->IntroduceExtensionIcon(newGWorld,newMask);
- }
-
- *(short *)0x160 = jbTempVBLMask;
- SetZone(saveZone);
- gGame->StartGame();
- }
-
-